package vip.xiaonuo.modular.controller;

import org.springframework.web.multipart.MultipartFile;
import vip.xiaonuo.core.annotion.BusinessLog;
import vip.xiaonuo.core.annotion.Permission;
import vip.xiaonuo.core.enums.LogAnnotionOpTypeEnum;
import vip.xiaonuo.core.pojo.page.PageResult;
import vip.xiaonuo.core.pojo.response.ResponseData;
import vip.xiaonuo.core.pojo.response.SuccessResponseData;
import vip.xiaonuo.core.util.PoiUtil;
import vip.xiaonuo.modular.entity.Result;
import vip.xiaonuo.modular.param.ResultParam;
import vip.xiaonuo.modular.service.ResultService;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.util.List;

/**
 * 考生成绩表控制器
 *
 * @author 春非昔日春
 * @date 2023-03-08 16:33:52
 */
@Controller
public class ResultController {

    private String PATH_PREFIX = "result/";

    @Resource
    private ResultService resultService;

    /**
     * 考生成绩表页面
     *
     * @author 春非昔日春
     * @date 2023-03-08 16:33:52
     */
    @Permission
    @GetMapping("/result/index")
    public String index() {
        return PATH_PREFIX + "index.html";
    }

    /**
     * 考生成绩表表单页面
     *
     * @author 春非昔日春
     * @date 2023-03-08 16:33:52
     */
    @GetMapping("/result/form")
    public String form() {
        return PATH_PREFIX + "form.html";
    }
    @GetMapping("/result/luqu")
    public String luqu() {
        return PATH_PREFIX + "luqu.html";
    }

    @GetMapping("/result/select")
    public String select() {
        return PATH_PREFIX + "select.html";
    }



    /**
     * 查询考生成绩表
     *
     * @author 春非昔日春
     * @date 2023-03-08 16:33:52
     */
    @Permission
    @ResponseBody
    @GetMapping("/result/page")
    @BusinessLog(title = "考生成绩表_查询", opType = LogAnnotionOpTypeEnum.QUERY)
    public PageResult<Result> page(ResultParam resultParam) {
        return resultService.page(resultParam);
    }

    /**
     * 添加考生成绩表
     *
     * @author 春非昔日春
     * @date 2023-03-08 16:33:52
     */
    @Permission
    @ResponseBody
    @PostMapping("/result/add")
    @BusinessLog(title = "考生成绩表_增加", opType = LogAnnotionOpTypeEnum.ADD)
    public ResponseData add(@RequestBody @Validated(ResultParam.add.class) ResultParam resultParam) {
        resultService.add(resultParam);
        return new SuccessResponseData();
    }

    /**
     * 删除考生成绩表
     *
     * @author 春非昔日春
     * @date 2023-03-08 16:33:52
     */
    @Permission
    @ResponseBody
    @PostMapping("/result/delete")
    @BusinessLog(title = "考生成绩表_删除", opType = LogAnnotionOpTypeEnum.DELETE)
    public ResponseData delete(@RequestBody @Validated(ResultParam.delete.class) List<ResultParam> resultParamList) {
        resultService.delete(resultParamList);
        return new SuccessResponseData();
    }

    /**
     * 编辑考生成绩表
     *
     * @author 春非昔日春
     * @date 2023-03-08 16:33:52
     */
    @Permission
    @ResponseBody
    @PostMapping("/result/edit")
    @BusinessLog(title = "考生成绩表_编辑", opType = LogAnnotionOpTypeEnum.EDIT)
    public ResponseData edit(@RequestBody @Validated(ResultParam.edit.class) ResultParam resultParam) {
        resultService.edit(resultParam);
        return new SuccessResponseData();
    }

    /**
     * 查看考生成绩表
     *
     * @author 春非昔日春
     * @date 2023-03-08 16:33:52
     */
    @Permission
    @ResponseBody
    @GetMapping("/result/detail")
    @BusinessLog(title = "考生成绩表_查看", opType = LogAnnotionOpTypeEnum.DETAIL)
    public ResponseData detail(@Validated(ResultParam.detail.class) ResultParam resultParam) {
        return new SuccessResponseData(resultService.detail(resultParam));
    }

    /**
     * 考生成绩表列表
     *
     * @author 春非昔日春
     * @date 2023-03-08 16:33:52
     */
    @Permission
    @ResponseBody
    @GetMapping("/result/list")
    @BusinessLog(title = "考生成绩表_列表", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData list(ResultParam resultParam) {
        return new SuccessResponseData(resultService.list(resultParam));
    }

    @ResponseBody
    @PostMapping("/result/import")
    @BusinessLog(title = "考生成绩表_导入", opType = LogAnnotionOpTypeEnum.IMPORT)
    public ResponseData importData( MultipartFile file) {
        return new SuccessResponseData(PoiUtil.importExcel(file,0,1,Result.class));
    }
}
